<template>
  <div>
    <el-form :model="formData" label-width="80px" class="form-box">
      <template v-for="formItem in formConfig">
        <el-form-item :key="formItem.prop" :label="formItem.label">
          <!-- input类型 -->
          <el-input
            v-if="formItem.type === 'input'"
            v-model="formData[formItem.prop]"
          />
          <!-- radio类型 -->
          <el-radio-group
            v-if="formItem.type === 'radio'"
            v-model="formData[formItem.prop]"
          >
            <el-radio
              v-for="optionItem in formItem.options"
              :key="optionItem.value"
              :label="optionItem.value"
            >{{ optionItem.label }}</el-radio>
          </el-radio-group>
          <!-- select类型 -->
          <el-select
            v-if="formItem.type === 'select'"
            v-model="formData[formItem.prop]"
            @change="formItem.callback(formData[formItem.prop])"
          >
            <el-option
              v-for="optionItem in formItem.options"
              :key="optionItem.value"
              :label="optionItem.label"
              :value="optionItem.value"
            />
          </el-select>
          <!-- 自定义类型 -->
          <template v-if="formItem.type === 'slot'">
            <slot :name="formItem.prop" />
          </template>
        </el-form-item>
      </template>
      <el-form-item>
        <el-button type="primary" @click="submitFn">提交</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'CommonForm',
  // props: ['formData', 'formConfig'],
  props: {
    formData: {
      type: Object,
      default: () => {}
    },
    formConfig: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {}
  },
  mounted() {},
  methods: {
    submitFn() {
      console.log(this.formData)
    }
  }
}
</script>
